import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:keyboard_avoider/keyboard_avoider.dart';
class MessageDialog extends Dialog {
  final ValueChanged<String> chooseCallback;
  Function onCloseEvent;
  Function onPositivePressEvent;

  MessageDialog({
    this.chooseCallback,
    this.onPositivePressEvent,
    @required this.onCloseEvent,
  });

  //中间视图背景
  Widget CenterBG(){
    return Container(
      decoration: ShapeDecoration(
        color: Color(0xffffffff),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(15.0),
          ),
        ),
      ),
      width:ScreenUtil().setWidth(403) ,
      height: ScreenUtil().setWidth(204),
    );
  }
  //中间视图
 Widget CenterWidget(){
   return Stack(
     children: <Widget>[
       CenterBG(),
       Positioned(
         child: inputWidget(),
         top:ScreenUtil().setWidth(52),
         left:ScreenUtil().setWidth(50),
       ),
       Positioned(
         child: Container(
             width: ScreenUtil().setWidth(280),
             height: ScreenUtil().setWidth(2),
             color: Color(0xffE8E8E8),
           ),
         top: ScreenUtil().setWidth(97),
         left: ScreenUtil().setWidth(64),
       ),
       Positioned(
         child: InkWell(
           onTap: this.onCloseEvent,
           child: Container(
               width: ScreenUtil().setWidth(126),
               height: ScreenUtil().setWidth(41),
               decoration: BoxDecoration(
                   borderRadius: BorderRadius.circular(8),
                   color:Color(0xffFFFFFF),
                   border: Border.all(
                   color: Color(0xff7086F8),
                   width: 1,
                   style: BorderStyle.solid
                )
              ),
              child: new Text('取消',style: TextStyle(fontSize: ScreenUtil().setSp(16),color: Color(0xff586FE9 )),textAlign: TextAlign.center),
              padding: EdgeInsets.only(top: ScreenUtil().setWidth(8)),
            ),
         ),
         left: ScreenUtil().setWidth(63),
         top: ScreenUtil().setWidth(126),
       ),
       Positioned(
         child: InkWell(
            onTap:this.onPositivePressEvent,
             child: Container(
               width: ScreenUtil().setWidth(126),
               height: ScreenUtil().setWidth(41),
               decoration: BoxDecoration(
                 borderRadius: BorderRadius.circular(8),
                 color:Color(0xffFFFFFF),
                 gradient: const LinearGradient(colors: [Color(0xff768CFC),Color(0xff586FE9)])
              ),
             child: new Text('确定',style: TextStyle(fontSize: ScreenUtil().setSp(16),color: Color(0xffFFFFFF)),textAlign: TextAlign.center,),
             padding: EdgeInsets.only(top: ScreenUtil().setWidth(8)),
           )
         ),
         left: ScreenUtil().setWidth(213),
         top: ScreenUtil().setWidth(126),
       ),
     ]
   );
 }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 1024, height: 640, allowFontScaling: true);
    return new Material(
        type: MaterialType.transparency,
        child: new Center(
          child: CenterWidget(),
        )
      );

  }

  Widget inputWidget(){
    return Container(
      height:ScreenUtil().setWidth(42),
      width: ScreenUtil().setWidth(281),
      child: TextField(
        textAlignVertical: TextAlignVertical.bottom,
        decoration: InputDecoration(
          fillColor: Color(0xffffffff),
          filled: true,
          border:OutlineInputBorder(borderSide: BorderSide.none),
          hintText: '请输入用户名',
        ),
        style: TextStyle(color: Color(0xff333333),fontSize: ScreenUtil().setSp(18),),textAlign: TextAlign.left,
        //文本内容改变时回调
        onChanged: (text) {
          print('文本内容改变时回调 $text');
          chooseCallback(text);
        },
        //内容提交时回调
        onSubmitted: (text) {
          print('内容提交时回调 $text');
        },
      ),
    );
  }


}